<template>
    <div class="system-menu-container">
        <div class="breadcrumb-box">
            <Breadcrumb />
        </div>
        <div class="page-read-edu-record">
            <div class="step-item" :class="{ 'step-item-border': isShowStep2 || isShowStep3 }">
                <div class="title-con">
                    <div class="icon-con icon-con-success">
                        <!-- <span>1</span> -->
                        <span><el-icon><Check /></el-icon></span>
                    </div>
                    <span style="margin-right: 20px;">已发送</span>
                    <span>{{info.education_time }}</span>
                </div>
                <div class="content-box">{{ info.sms }}</div>
                <div class="tips-con">宣教文档：<el-text @click="handleShowPdf" style="cursor: pointer;" size="small" type="primary">{{info.education_template && info.education_template.name}}</el-text></div>
            </div>
            <div class="step-item" :class="{'step-item-border': isShowStep3}" v-if="isShowStep2 || isShowStep3">
                <div class="title-con">
                    <div class="icon-con">
                        <span>2</span>
                        <!-- <span><el-icon><Check /></el-icon></span> -->
                    </div>
                    <span style="margin-right: 20px;">已查看</span>
                    <span>{{ info.see_time}}</span>
                </div>
            </div>
            <div class="step-item" v-if="isShowStep3">
                <div class="title-con">
                    <div class="icon-con">
                        <span>3</span>
                        <!-- <span><el-icon><Check /></el-icon></span> -->
                    </div>
                    <span style="margin-right: 20px;">已回复</span>
                    <span>{{info.reply && info.reply.created_at }}</span>
                </div>
                <div class="content-box">{{info.reply && info.reply.content }}</div>
                <template v-if="info.reply && info.reply.content_url.length > 0">
                    <div class="tips-con" >
                        照片：
                        <el-text 
                        v-for="(v, index) in info.reply.content_url" 
                        :key="index" 
                        @click="handleShowViewer(index)" 
                        style="cursor: pointer;margin-right: 10px" 
                        size="small" 
                        type="warning">照片{{index + 1}}</el-text>
                    </div>
                </template>
            </div>
        </div>
        <el-image-viewer 
            @close="closeImgViewer" 
            :initial-index="viewerIndex"
            :url-list="previewList" v-if="showImageViewer"/>
        <el-dialog
            v-model="pdfPreview"
            :title="info.education_template && info.education_template.name"
            :close-on-press-escape="false"
            :close-on-click-modal="false"
            width="80%">
            <div class="pdf-con">
                <object 
                    v-if="info.education_template && info.education_template.content" 
                    :data="info.education_template && info.education_template.content" 
                    type="application/pdf" width="100%" height="100%">
                        <param name="view" value="FitH">
                </object>
            </div>
        </el-dialog>
    </div>
</template>
<script setup>
import { educationGetRecordDetail } from "/@/api/education";
// 引入组件
import { Check } from "@element-plus/icons-vue";
import { useRoute } from "vue-router";
import { computed, onMounted, ref } from "vue";
const Breadcrumb = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/breadcrumb.vue'));
const route = useRoute()
const previewList = ref([])
const showImageViewer = ref(false)
const pdfPreview = ref(false)

onMounted(()=>{
    getDetail()
})

const isShowStep2 = computed(()=>info.value.status == 2)
const isShowStep3 = computed(()=>info.value.status == 3)
const viewerIndex = ref(0)

const closeImgViewer = ()=>{
    showImageViewer.value = false
}
const handleShowPdf = () =>{
    pdfPreview.value = true
}
const handleShowViewer = (index)=>{
    viewerIndex.value = index
    showImageViewer.value = true
}

const info = ref({})
const getDetail = async () =>{
    const res = await educationGetRecordDetail({id: route.query.id})
    info.value = res.data
    previewList.value = res.data.reply.content_url
}
</script>
<style lang="scss" scoped>
.system-menu-container {
    height: calc(100vh - 70px);
}
.page-read-edu-record {
    background-color: #fff;
    width: calc(100% - 20px);
    margin-left: 10px;
    height: calc(100% - 50px);
    margin-top: 10px;
    border-radius: 4px;
    overflow: hidden;
    box-sizing: border-box;
    padding: 20px;
    .step-item {
        padding-bottom: 30px;
        .title-con {
            display: flex;
            align-items: center;
            .icon-con {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 40px;
                height: 40px;
                border: 1px solid #1890FF;
                border-radius: 50%;
                font-size: 20px;
                color: #333;
                margin-right: 20px;
                background-color: #1890FF;
                color: #fff;
            }
            .icon-con-success {
                background-color: transparent;
                color: #1890FF;
            }
        }
        .content-box {
            margin-left: 60px;
            background-color: #F2F2F2;
            border: 1px solid #ccc;
            padding: 10px 20px;
            min-height: 80px;
            border-radius: 4px;
            margin-right: 40px;
        }
        .tips-con {
            margin-left: 60px;
            margin-top: 10px;
        }

    }
     .step-item-border {
        position: relative;
        &::before {
            position: absolute;
            content: '';
            top: 45px;
            bottom: 5px;
            width: 2px;
            background-color: #1890FF;
            left: 20px;
        }
     }
    }
    .pdf-con {
       height: 600px;
        padding-bottom: 20px;
    }
</style>